package com.bootdo.wx.api;

import com.bootdo.common.utils.R;
import com.bootdo.wx.domain.CmsNoticeSysDO;
import com.bootdo.wx.service.CmsNoticeSysService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by Administrator.
 *
 * @autor L - 2020/5/22 - 9:24.
 */

@Controller
@RequestMapping("/api/cms")
public class ApiCmsController {
    @Autowired
    private CmsNoticeSysService cmsNoticeSysService;

    /**
     * 我的消息（公告）列表
     */
    @PostMapping("/noticeSys/list")
    @ResponseBody
    public R noticeSysList(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("pageNumber") || !params.containsKey("pageSize")) {
            return R.error("参数异常");
        }
        try {
            PageInfo<CmsNoticeSysDO> list = cmsNoticeSysService.queryAll(params);
            return R.ok().put("data", list);
        } catch (Exception e) {
            return R.error("服务器网络异常");
        }
    }

    /**
     * 系统公告详情
     */
    @PostMapping("/noticeSys/info")
    @ResponseBody
    public R noticeSysInfo(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("noticeSysId")) {
            return R.error("参数异常");
        }
        try {
            String noticeSysId = params.get("noticeSysId").toString();
            CmsNoticeSysDO list = cmsNoticeSysService.get(noticeSysId);
            return R.ok().put("data", list);
        } catch (Exception e) {
            return R.error("服务器网络异常");
        }
    }

}
